<?php
class rewrite_link{
	function slug($string, $spaceRepl = "-") {
	  // Replace "&" char with "and"
	  $string = str_replace("&", "and", $string);
	
	  // Delete any chars but letters, numbers, spaces and _, -
	  $string = preg_replace("/[^a-zA-Z0-9 _-]/", "", $string);
	
	  // Optional: Make the string lowercase
	  $string = strtolower($string);
	
	  // Optional: Delete double spaces
	  $string = preg_replace("/[ ]+/", " ", $string);
	
	  // Replace spaces with replacement
	  $string = str_replace(" ", $spaceRepl, $string);
	
	  return $string;
	}
}